﻿namespace GuiaTest
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Guia.Core;
    using Guia.Elements;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using WpfTestApplication;

    /// <summary>
    /// Summary description for DatePickerTest
    /// </summary>
    [TestClass]
    public class DatePickerTest : AbstractWindowTest
    { 
        [TestMethod]
        public void TestExpandCollapse()
        {
            DatePicker datePicker1 = this.window.Get<DatePicker>("datePicker1");
            Assert.IsFalse(datePicker1.IsExpanded);
            datePicker1.Expand();
            Assert.IsTrue(datePicker1.IsExpanded);
            datePicker1.Collapse();
            Assert.IsFalse(datePicker1.IsExpanded);
        }

        [TestMethod,ExpectedException(typeof(OperationNotSupportedException))]
        public void TestExpandDisabled()
        {
            DatePicker datePicker3 = this.window.Get<DatePicker>("datePicker3");
            datePicker3.Expand();
        }

        [TestMethod, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestCollapseDisabled()
        {
            DatePicker datePicker3 = this.window.Get<DatePicker>("datePicker3");
            datePicker3.Collapse();
        }

        [TestMethod]
        public void TestIsExpanded()
        {
            DatePicker datePicker1 = this.window.Get<DatePicker>("datePicker1");
            Assert.IsFalse(datePicker1.IsExpanded);
            datePicker1.IsExpanded = true;
            Assert.IsTrue(datePicker1.IsExpanded);
            datePicker1.IsExpanded = true;
            Assert.IsTrue(datePicker1.IsExpanded);
            datePicker1.IsExpanded = false;
            Assert.IsFalse(datePicker1.IsExpanded);
            datePicker1.IsExpanded = false;
            Assert.IsFalse(datePicker1.IsExpanded);
        }

        [TestMethod]
        public void TestDate()
        {
            DatePicker datePicker1 = this.window.Get<DatePicker>("datePicker1");
            DateTime date = DateTime.Parse("10.06.2010");
            datePicker1.Date = date;
            Assert.AreEqual(date, datePicker1.Date);
        }

        [TestMethod,ExpectedException(typeof(OperationNotSupportedException))]
        public void TestDateWasNotSet()
        {
            DatePicker datePicker1 = this.window.Get<DatePicker>("datePicker1");
            DateTime date = datePicker1.Date;
        }

        [TestMethod]
        public void TestTryGetDate()
        {
            DatePicker datePicker1 = this.window.Get<DatePicker>("datePicker1");
            DateTime date = DateTime.Parse("10.06.2010");
            DateTime date2;
            datePicker1.Date = date;
            bool result = datePicker1.TryGetDate(out date2);
            Assert.IsTrue(result);
            Assert.AreEqual(date,date2);
        }

        [TestMethod]
        public void TestTryGetDateWasNotSet()
        {
            DatePicker datePicker1 = this.window.Get<DatePicker>("datePicker1");
            DateTime date;
            bool result = datePicker1.TryGetDate(out date);
            Assert.IsFalse(result);
        }

        [TestMethod,ExpectedException(typeof(OperationNotSupportedException))]
        public void TestSetDateDisabled()
        {
            DatePicker datePicker3 = this.window.Get<DatePicker>("datePicker3");
            DateTime date = DateTime.Parse("10.06.2010");
            datePicker3.Date = date;
        }

        [TestMethod]
        public void TestTextValue()
        {
            DatePicker datePicker1 = this.window.Get<DatePicker>("datePicker1");
            DatePicker datePicker2 = this.window.Get<DatePicker>("datePicker2");
            DateTime date = DateTime.Parse("10.05.2010");
            datePicker1.Date = date;
            datePicker2.Date = date;
            Assert.AreEqual("10.05.2010", datePicker1.TextValue);
            Assert.AreEqual("Montag, 10. Mai 2010", datePicker2.TextValue);
        }

        #region Overrides of AbstractWindowTest

        protected override Type TestWindowType()
        {
            return typeof (DatePickerTestWindow);
        }

        protected override string TestWindowName()
        {
            return "DatePickerTestWindow";
        }

        #endregion
    }
}
